package cn.tth.test.model.proxy;


//import cn.tth.test.rabbitmq.MqConfig;
import com.alibaba.fastjson.JSON;
import jdk.dynalink.beans.StaticClass;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibProxy implements MethodInterceptor {


    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        if(objects.length == 2){
            System.out.println("替换值");
            Object o0 = objects[0];
            Object o1 = objects[1];
            objects[0] = 3;
            objects[1] = 5;
        }
        Object result = methodProxy.invokeSuper(o, objects);
        if(result instanceof Boolean){


        }
        return result;
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(A.class);
        enhancer.setCallback(new CglibProxy());

        A a = (A) enhancer.create();

        String s = a.get(1, 2);
        System.out.println(s);
    }

    public static class A{

        public String get(Integer i,Integer i1){
            System.out.println(i);
            System.out.println(i1);
            return "A";
        }
    }
}
